package com.msb.serviceverificationcode.controller;

import com.alibaba.fastjson.JSONObject;
import com.msb.internalcommon.dto.ResponseResult;
import com.msb.internalcommon.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: WuWen
 * @Date: 2023/3/1 - 03 - 01 - 16:29
 * @Description: com.msb.serviceverificationcode.controller
 * @version: 1.0
 */
@RestController
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size){

        // 生成验证码
        System.out.println("size" + size);
        double num = (Math.random()*9+1)*(Math.pow(10,size-1));
        int resultInt = (int)num;
        System.out.println("生成验证码：" + resultInt);

        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(resultInt);

        /* //用json传递返回值
        JSONObject result = new JSONObject();
        result.put("code",1);
        result.put("message","success");
        JSONObject data = new JSONObject();
        data.put("numberCode",resultInt);
        result.put("data",data);*/
        return ResponseResult.success(response);
    }


}
